package com.bsoft.ecommerce.conf;

import com.bsoft.ecommerce.filter.LoginUserInfoInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

//  配置拦截器
@Configuration
public class ImoocWebMvcConfig extends WebMvcConfigurationSupport {
    //添加拦截器配置
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        // 添加用户身份统一登录的拦截的拦截器
        registry.addInterceptor(new LoginUserInfoInterceptor()).addPathPatterns("/**").order(0);
    }

    // 让mvc 加载swagger的静态资源
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/"
        );
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath://META-INF/resource/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath://META-INF/resource/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath://META-INF/resource/webjars");
        super.addResourceHandlers(registry);
    }
}
